package practice.councilling;

import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;

public class Main {

	Node source,sink;
	//All nodes (it doesn't matter whether source and sink are there).
	List<Node> nodesList;
	
	
	public int maxFlow(){
		
		int flow =0;
		
		while (bfs()){
			
			flow+=update();
		}
		
		return flow;
	}
	public int update(){
		
		int ret = Integer.MAX_VALUE;
		
		Edge current = sink.used;
		
		while (current!=null){
			
			ret = Math.min(ret, current.reverse.capacity);
			
			current = current.to.used;
		}
		
		current = sink.used;
		
		while (current!=null){
			
			current.capacity+=ret;
			
			current.reverse.capacity-=ret;
			
			current = current.to.used;
		};
		return ret;
	}
	/**
	 * BFS on flow problem
	 * @param nodesList The list of all nodes
	 * @return
	 */
	public boolean bfs(){
		
		for (Node n : nodesList){ n.marked = false; n.used =null;}
		
		Queue<Edge>queue = new LinkedList<Edge>();
		
		source.marked = true;
		
		sink.marked=false;
		
		queue.offer(new Edge(source, 0));
		
		while (!queue.isEmpty()){
			
			Edge current = queue.poll();
			
			if (current.to==sink)
				return true;
			
			for (Edge e: current.to.edges)
				
				if (e.capacity>0 && !e.to.marked){
					
					queue.offer(e);
					
					e.to.used=e.reverse;
					
					e.to.marked = true;
				}
		}
		return false;
	}
	class Node{
		
		Edge used;
		boolean marked;
		String id;
		List<Edge> edges;
		
		public Node(String id){
			
			edges = new LinkedList<Edge>();
			marked = false; this.id=id;
		}
	}
	class Edge{
		
		int capacity;
		Edge reverse;
		Node to;
		
		public Edge (Node to, int capacity){
			
			this.to = to;
			this.capacity = capacity;
		}
	}
	
	public Main() {
		Scanner s = new Scanner(System.in);
		int numCase=s.nextInt();
		s.nextLine();s.nextLine();
		
		for (int i =0; i < numCase; i++){
			Set<String> parties = new HashSet<String>();
			Set<String> clubs = new HashSet<String>();
			Map<String,Person> people = new HashMap<String,Person>();
			Map<String,Node> partyMap = new HashMap<String,Node>();
			Map<String,Node> clubMap = new HashMap<String,Node>();
			
			nodesList = new LinkedList<Node>();
			source = new Node("source");
			sink = new Node("sink");
			
			while(true){
				String line =s.nextLine();
				if (line.equals(""))
					break;
				Scanner ls = new Scanner(line);
				Person p = new Person(new Node(ls.next()),ls.next());
				nodesList.add(p.n);
				while (ls.hasNext())
					p.clubs.add(ls.next());
				people.put(p.n.id, p);
				parties.add(p.party);
				for (String cl : p.clubs)
					clubs.add(cl);
			}
			int partyCap=clubs.size()/2-1;
			if (clubs.size()%2 ==1)
				partyCap++;
			for (String part: parties){
				Node n = new Node(part);
				partyMap.put(part, n);
				nodesList.add(n);
				
				Edge e = new Edge(sink,partyCap);
				Edge ee = new Edge(n,0);
				e.reverse=ee;
				ee.reverse=e;
				n.edges.add(e);
				sink.edges.add(ee);
			}
			
			for (String club: clubs){
				Node n = new Node(club);
				clubMap.put(club, n);
				nodesList.add(n);
				
				Edge e = new Edge(n,1);
				Edge ee = new Edge(source,0);
				e.reverse=ee;
				ee.reverse=e;
				source.edges.add(e);
				n.edges.add(ee);
			}
			
			for (String p: people.keySet()){
				Person per = people.get(p);
				
				Edge e = new Edge(partyMap.get(per.party),1);
				Edge ee = new Edge(per.n,0);
				e.reverse=ee;
				ee.reverse=e;
				per.n.edges.add(e);
				partyMap.get(per.party).edges.add(ee);
				
				for (String club: per.clubs){
					
					e = new Edge(per.n,1);
					ee = new Edge(clubMap.get(club),0);
					e.reverse=ee;
					ee.reverse=e;
					clubMap.get(club).edges.add(e);
					per.n.edges.add(ee);
				}
			}
			int mf = maxFlow();
			if (mf < clubs.size() || clubs.size() ==0){
				System.out.println("Impossible.");
			}
			else{
				for (String club: clubs){
					Node c = clubMap.get(club);
					for (Edge e : c.edges){
						if (e.to != source && e.capacity ==0){
							System.out.println(e.to.id+" "+club);
						}
					}
				}
			}
			if (i < numCase-1)
				System.out.println("");
		}
	}
	
	class Person{
		String party;
		List<String> clubs;
		Node n;
		public Person(Node n,String party){this.n=n;this.party=party;clubs=new LinkedList<String>();}
	}

	public static void main(String[] args) {
		new Main();
	}

}
